package main

import "fmt"

//演示多重继承
func main() {
	tv1 := TV1{
		Goods{
			Name:  "商品1",
			Price: 10.1,
		},
		Brand{
			Name:    "品牌1",
			Address: "品牌1地址",
		},
	}
	fmt.Println(tv1)
	//报错，因为Goods和Brand都有Name，而TV1本身无Name，所以这个时候编译器就不知道你这个Name到底要给谁赋值
	// fmt.Println(tv1.Name)
	tv2 := TV2{
		&Goods{
			Name:  "商品1",
			Price: 10.1,
		},
		&Brand{
			Name:    "品牌1",
			Address: "品牌1地址",
		},
	}
	fmt.Println(tv2)
	fmt.Println(*tv2.Goods)
	fmt.Println(*tv2.Brand)
}

type Goods struct {
	Name  string
	Price float64
}

type Brand struct {
	Name    string
	Address string
}

type TV1 struct {
	Goods
	Brand
}

type TV2 struct {
	*Goods
	*Brand
}
